﻿using System;

namespace SeoulOpenApi.Water
{
	/// <summary>
	/// 서울시 Open API 수질 정보
	/// </summary>
	public class WaterService : BaseService
	{
		/// <summary>
		/// 서울시 API 서비스
		/// </summary>
		public WaterService() : this(null, null) { }

		/// <summary>
		/// 서울시 API 서비스
		/// </summary>
		/// <param name="userId">서울시 API접속 ID</param>
		/// <param name="authKey">서울시로부터 발급받은 인증키</param>
		/// <remarks>인증키 발급: http://mobile.openapi.seoul.go.kr/ </remarks>
		public WaterService(string userId, string authKey)
		{
			base.UserID = userId;
			base.AuthKey = authKey;
		}


		/// <summary>
		/// 서비스 항목에 따라 데이터 가져오기
		/// </summary>
		/// <param name="name">서비스명</param>
		/// <returns></returns>
		protected override SoapData getSoapData(string name)
		{
			var soap = new SoapData { Address = new Uri(ApiUrlPrefix + "WaterQualityService?wsdl", UriKind.Absolute) };
			switch (name)
			{
				case "searchWaterGuList":
					soap.Name = "searchWaterGuList";
					soap.Description = "수질 지역 목록(구) 조회";
					soap.SoapBody = "<ns:searchWaterGuList xmlns:ns='http://service.water.openapi.ubizvalley.com'></ns:searchWaterGuList>";
					break;
				case "searchWaterDongList":
					soap.Name = "searchWaterDongList";
					soap.Description = "수질 지역 목록(동) 검색";
					soap.SoapBody = "<ns:searchWaterDongList xmlns:ns='http://service.water.openapi.ubizvalley.com'>" +
									"<ns:gucode>{0}</ns:gucode>" + // 변수: 구지역코드
									"</ns:searchWaterDongList>";
					break;
				case "searchWaterQualityList":
					soap.Name = "searchWaterQualityList";
					soap.Description = "지역별 수질 현황 정보 제공";
					soap.SoapBody = "<ns:searchWaterQualityList xmlns:ns='http://service.water.openapi.ubizvalley.com'>" +
									"<ns:gucode>{0}</ns:gucode>" + // 변수: 구지역코드
									"<ns:dongcode>{1}</ns:dongcode>" + // 변수: 동지역코드
									"</ns:searchWaterQualityList>";
					break;
			}

			// 해당 서비스가 없는 경우
			if (String.IsNullOrEmpty(soap.Name))
				throw new Exception(name + " not found.");

			return soap;
		}
	}
}
